package com.clayecloud.common.admin.services.Impl;

import com.clayecloud.common.admin.services.VisitorService;
import com.clayecloud.common.entity.House;
import com.clayecloud.common.entity.Visitor;
import com.clayecloud.common.mappers.VisitorMapper;
import com.clayecloud.common.utils.MessageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("AdminVisitorServiceImpl")
public class VisitorServiceImpl implements VisitorService {

    @Resource
    private VisitorMapper visitorMapper;

    @Override
    public MessageUtil updateByPrimaryKeySelective(Visitor record) {
        return visitorMapper.updateByPrimaryKeySelective(record) > 0 ? MessageUtil.success("修改成功") : MessageUtil.fail("修改失败");
    }

    @Override
    public MessageUtil selectAll(Integer size, Integer page) {
        PageHelper.startPage(page,size);
        List<Visitor> visitors = visitorMapper.selectAll();
        PageInfo pageInfo = new PageInfo(visitors);
        Map result = new HashMap();
        result.put("list",visitors);
        result.put("total",pageInfo.getTotal());
        return MessageUtil.success("查询成功").add(result);
    }
}
